package com.z6school.manage.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.z6school.manage.common.annotation.RequiredLog;
import com.z6school.manage.common.pojo.PageObject;
import com.z6school.manage.mapper.LogsMapper;
import com.z6school.manage.po.Log;
import com.z6school.manage.po.Teacher;
import com.z6school.manage.service.LogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogsMapper logsMapper;


    @Override
    @RequiresPermissions("sys:log:view")
    public PageObject<Log> findObjects(String username, Integer pageCurrent) {
        //1.参数校验
        if(pageCurrent == null || pageCurrent<1)
            throw new IllegalArgumentException("页码值不正确");
        //2.PageHelper
        Page<Object> page = PageHelper.startPage(pageCurrent, 5);
        List<Log> logList = logsMapper.selectList(null);
        //3.封装结果
        return new PageObject<Log>( page.getTotal(), logList, (long) page.getPages(), 5, pageCurrent);
    }

    @Override
    @RequiredLog(operation = "删除日志信息")
    @RequiresPermissions("sys:log:delete")
    public int deleteObjects(Integer... ids) {
        int rows = logsMapper.deleteObjects(ids);
        return rows;
    }

    @Override
    public void saveObject(Log log) {
        logsMapper.insert(log);
    }
}
